package com.hcz.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hcz.dao.UserDao;
import com.hcz.entity.User;

public class CreateServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
			String username = request.getParameter("username");
			String password = request.getParameter("password");
			String m = request.getParameter("money");
			 
			System.out.println(username);
			System.out.println(password);
			System.out.println(m);
			if(username == null || password == null || m == null){
				
				response.sendRedirect("index.jsp");
				return ;
			}
			User user = new User();
			user.setName(username);
			user.setPassword(password);
			user.setMoney(Float.parseFloat(m));
			user.setState(true);
			
			UserDao ud = new UserDao();
			int num = ud.createAccount(user);
			
			if(num > 0 ){
				
				response.sendRedirect("loginIndex.jsp");
				return ;
			}else {
				response.sendRedirect("index.jsp?code=1002");
				return ;
			}
			
			
	}

}
